/*
 * Public Credit Information Sharing Platform(PCISP).
 * Copyright (c) 2019-2020 jsxzkingdee and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * Please visit https://www.zhengxinsoft.com if you need additional information or have any questions.
 */

package com.platform.core.limit;

import com.platform.comm.constants.GlobalConstant;
import com.platform.comm.util.HttpUtil;
import com.platform.comm.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * Description: 浏览量切面
 *
 * @author libin created on 2020/5/8.
 */
@Slf4j
@Aspect
@Component
public class HyperLogAspect {

    private final RedisUtil redisUtil;

    public HyperLogAspect(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    @Before(value = "@annotation(hyperLogLimit) && args(id)")
    public void before(HyperLogLimit hyperLogLimit, String id) {
        try {
            String value = HttpUtil.getIpAddress();
            String key = GlobalConstant.BASE_REDIS_CACHE_PREFIX + hyperLogLimit.name() + ":" + id;
            redisUtil.add(key, value);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
